var qrcodeParm="";
var userRecommendId = "";
$(function () {
    extension()
    //图片ID
    var imgId =GetQueryString("imgId")
    //用户推荐码
    var qrCode = GetQueryString("recommendId")
    debugger;
    if (userRecommendId==-1) {
        //接受邀请用户
        accept(imgId)
        qrcodeParm = getContextPath()+"/register.html?recommendId=" + qrCode
    } else if(userRecommendId!=-1&&userRecommendId!=qrCode){
        //推荐给已经注册的用户
        friends(imgId);
    }else{
        //推荐给自己
        img(imgId)
    }
    $("#copy").click(function(){
    	 var input = document.getElementById("url");
	   	 input.select();
	   	 document.execCommand("copy"); 
	   	 $("#alert1").modal()
    })
})

/**
 * 推荐用户
 * @param imgId
 */
function img(imgId) {
    var html = ""
    if (imgId == 'Extension1') {
        html = "<iframe src=\"https://c.xiumi.us/stage/v5/2NnvH/87148172\" width=\"100%\" height=\"100%\" frameborder=\"0\">"
    } else if (imgId == 'Extension2') {
        html = "<iframe src=\"http://u7007795.viewer.maka.im/k/S3XP3RYK\" width=\"100%\" height=\"100%\" frameborder=\"0\">"
    }
    else {
        alert("系统错误")
    }
    $("#iframe").append(html)
    //获取本页面的url
    var url = window.location.href
    //分享链接
    $("#url").val(url);
}

/**
 * 接受邀请
 */
function accept(imgId) {
    var html = ""
    if (imgId == 'Extension1') {
        html = "<iframe src=\"https://c.xiumi.us/stage/v5/2NnvH/87148172\" width=\"100%\" height=\"100%\" frameborder=\"0\">"
    } else if (imgId == 'Extension2') {
        html = "<iframe src=\"http://u7007795.viewer.maka.im/k/S3XP3RYK\" width=\"100%\" height=\"100%\" frameborder=\"0\">"
    }
    else {
        alert("系统错误")
    }
    $("#iframe").append(html)
    $("#qrcode").html("<span onclick='redirect()' style='width:100%;background:#fff;height:40px;line-height:40px;text-align:center;display:inline-block;position:fixed;bottom:0;'>接受邀请,立即注册<span/>");
}
//friends
function friends(imgId) {
    var html = ""
    if (imgId == 'Extension1') {
        html = "<iframe src=\"https://c.xiumi.us/stage/v5/2NnvH/87148172\" width=\"100%\" height=\"100%\" frameborder=\"0\">"
    } else if (imgId == 'Extension2') {
        html = "<iframe src=\"http://u7007795.viewer.maka.im/k/S3XP3RYK\" width=\"100%\" height=\"100%\" frameborder=\"0\">"
    }
    else {
        alert("系统错误")
    }
    $("#iframe").append(html)
    //获取本页面的url
    var url = getContextPath()+"/personal/extension.html?recommendId=" + userRecommendId+"&imgId="+imgId
    //分享链接
    $("#friends").html("你已是注册用户,复制链接分享给好友进行推广:");
    $("#url").val(url)
}
/**
 * 跳转到注册页面
 */
function redirect() {
    window.location.href = qrcodeParm
}

function extension() {
    slf.ajax({
        url: '/extension',
        type: 'post',
        async: false,
        success: function (data) {
                userRecommendId=data
        }
    })
}
